package com.example.mall.service.impl;

import com.example.mall.mbg.mapper.CustomDataMapper;
import com.example.mall.mbg.mapper.CustomScoreMapper;
import com.example.mall.mbg.mapper.DataMapper;
import com.example.mall.mbg.model.Data;
import com.example.mall.mbg.model.DataExample;
import com.example.mall.mbg.model.Score;
import com.example.mall.service.DataService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * DataServiceImpl
 * Created by on 2023/12/27.
 */
@Service
public class DataServiceImpl implements DataService {
    @Autowired
    private DataMapper dataMapper;
    @Autowired
    private CustomDataMapper customDataMapper;

    @Override
    public List<Data> listAll() {
        return dataMapper.selectByExample(new DataExample());
    }

    @Override
    public int create(Data data) {
        return dataMapper.insertSelective(data);
    }

    @Override
    public int update(Integer dataid, Data data) {
        data.setDataid(dataid);
        return dataMapper.updateByPrimaryKeySelective(data);
    }

    @Override
    public int delete(Integer dataid) {
        return dataMapper.deleteByPrimaryKey(dataid);
    }

    @Override
    public List<Data> list(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return dataMapper.selectByExample(new DataExample());
    }

    @Override
    public Data get(Integer dataid) {
        return dataMapper.selectByPrimaryKey(dataid);
    }

    @Override
    public int getNextId() {
        return customDataMapper.getNextId();
    }

    @Override
    public void deleteAll() {
        customDataMapper.deleteAll();
    }
}
